| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- // app/api/branches/[branch]/[year]/[month]/days/route.test.js
- import { describe, it, expect, beforeAll, afterAll } from "vitest";
- import fs from "node:fs/promises";
- import os from "node:os";
- import path from "node:path";
- import { GET as getDays } from "./route.js";
- let tmpRoot;
- beforeAll(async () => {
- tmpRoot = await fs.mkdtemp(path.join(os.tmpdir(), "api-days-"));
- process.env.NAS_ROOT_PATH = tmpRoot;
- // tmpRoot/NL01/2024/10/23
- await fs.mkdir(path.join(tmpRoot, "NL01", "2024", "10", "23"), {
- recursive: true,
- });
- });
- afterAll(async () => {
- await fs.rm(tmpRoot, { recursive: true, force: true });
- });
- describe("GET /api/branches/[branch]/[year]/[month]/days", () => {
- it("returns days for a valid branch/year/month", async () => {
- const req = new Request("http://localhost/api/branches/NL01/2024/10/days");
- const ctx = {
- params: Promise.resolve({
- branch: "NL01",
- year: "2024",
- month: "10",
- }),
- };
- const res = await getDays(req, ctx);
- expect(res.status).toBe(200);
- const body = await res.json();
- expect(body).toEqual({
- branch: "NL01",
- year: "2024",
- month: "10",
- days: ["23"],
- });
- });
- it("returns 400 when any param is missing", async () => {
- const req = new Request("http://localhost/api/branches/NL01/2024/10/days");
- const ctx = {
- params: Promise.resolve({ branch: "NL01", year: "2024" }), // month missing
- };
- const res = await getDays(req, ctx);
- expect(res.status).toBe(400);
- const body = await res.json();
- expect(body.error).toBe("branch, year oder month fehlt");
- });
- });
|